cmake_minimum_required(VERSION 3.13)

include(FetchContent)

project(nod)

if(NOT DEFINED NOD_NODE_VERSION)
    set(NOD_NODE_VERSION v13.8.0)
endif()

if(NOT DEFINED NOD_NODE_OS)
    if (UNIX)
        if (APPLE)
            set(NOD_NODE_OS darwin)
        else()
            set(NOD_NODE_OS linux)
        endif()
    else()
        set(NOD_NODE_OS win32)
    endif()
endif()

if(NOT DEFINED NOD_NODE_ARCH)
    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
        set(NOD_NODE_ARCH x86)
    else()
        set(NOD_NODE_ARCH x64)
    endif()
endif()

if(NOT DEFINED NOD_NODE_CONFIG)
    set(NOD_NODE_CONFIG "-nointl")
endif()

message("fetching https://gitee.com/aliencoder/libnode/attach_files/937943/download/libnode-${NOD_NODE_VERSION}-${NOD_NODE_OS}-${NOD_NODE_ARCH}${NOD_NODE_CONFIG}.zip")
FetchContent_Declare(
    libnode
    URL https://gitee.com/aliencoder/libnode/attach_files/937943/download/libnode-${NOD_NODE_VERSION}-${NOD_NODE_OS}-${NOD_NODE_ARCH}${NOD_NODE_CONFIG}.zip
)
FetchContent_MakeAvailable(libnode)

add_library(nod STATIC src/nod.cc)
set_property(TARGET nod PROPERTY CXX_STANDARD 11)

target_include_directories(nod PUBLIC src/include)
target_link_libraries(nod libnode)

if("${NOD_ENABLE_TEST}" EQUAL "1")
    add_subdirectory(test)
endif()
